package com.example.views;

import com.example.presenters.ProfilePresenter;
import com.example.R;
import com.example.interfaces.IProfileActivity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

/**
 * This is the ProfileActivity. It shows the profile view to users, let's them
 * take a desired action, and moves the user to the appropriate activity.
 * 
 * @author 3Factorial
 */
public class ProfileActivity extends Activity implements IProfileActivity {

	private ProfilePresenter myPresenter;
	private String currUserName;

	/**
	 * Activates the Profile Activity with the appropriate information.
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_profile);
		myPresenter = new ProfilePresenter(this,
				com.example.model.UserList.getInstance());
		Intent intent = getIntent();

		currUserName = intent.getStringExtra(MainActivity.USERNAME);
		TextView userNameView = (TextView) findViewById(R.id.text_title_profile);
		userNameView.setText(currUserName);

		ListView lostItem = (ListView) findViewById(R.id.myList);
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
				R.layout.simplerow, myPresenter.getLostItemList(currUserName));
		lostItem.setAdapter(adapter);
		
		ListView foundItem = (ListView) findViewById(R.id.foundList);
		ArrayAdapter<String> adapterFound = new ArrayAdapter<String>(this,
				R.layout.simplerow, myPresenter.getFoundItemList(currUserName));
		foundItem.setAdapter(adapterFound);
		

		Button adminButton = (Button) findViewById(R.id.button_admin);
		myPresenter.hideAdminButton(adminButton, currUserName);
	}

	/**
	 * Loads the menu options.
	 */
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	// Javadoc from interface
	public void postItem(View view) {
		Intent intent = new Intent(this, PostItemActivity.class);
		intent.putExtra(MainActivity.USERNAME, currUserName);
		startActivity(intent);
	}

	/**
	 * Logs the user out.
	 * 
	 * @param view
	 *            The MainActivity.
	 */
	public void logout(View view) {
		Intent intent = new Intent(this, MainActivity.class);
		startActivity(intent);
	}

	/**
	 * Sends the user to the Admin view.
	 * 
	 * @param view
	 *            Admin view.
	 */
	public void admin(View view) {
		Intent intent = new Intent(this, AdminActivity.class);
		intent.putExtra(MainActivity.USERNAME, currUserName);
		startActivity(intent);
	}

	/**
	 * Sends the user to the ItemListActivity to view all items.
	 */
	public void goToItems(View view) {
		Intent intent = new Intent(this, ItemListActivity.class);
		startActivity(intent);
	}

}
